package it.uniroma3.dia.ia.textcategorization.utils;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import it.uniroma3.dia.ia.textcategorization.model.Text;

/**
 * 
 * Utility class to use to retrieve a web page as Text instance.
 * 
 * @author Marco Liceti
 *
 */
public final class PageRetriever {

	/**
	 * 
	 * Retrieves a web page as Text instance.
	 * 
	 * @param link The string containing the link to the web page to retrieve.
	 * @return a newly created Text instance corresponding to the web page requested.
	 */
	public static Text retrieve(String link) {
		Text text = null;
		try {
			URL url = new URL(link);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			return new Text(connection.getInputStream());
		} catch (IOException exeption) {
			// In case of an exception,
			// simply return null
		}
		return text;
	}

}
